#include <iostream>
#include "stdlib.h"

using namespace std; 

struct Base{
   char *name;
   Base(char *n) : name(strdup(n)){ cout << "Base ctor caller\n"; }
   Base& operator= (const Base& other){
    free (name);
    name = strdup (other.name);
    cout << "Base assignment called\n";
   }
 };
 
 struct A: virtual Base{
   int val;
   A():Base((char *)"A"){ cout << "Class A ctor called\n"; }
 };
 
 struct B:virtual Base{
   int bval;
   B():Base((char *)"B"){ cout << "Class B ctor called\n"; }
 };
 
 struct Derived:public A, public B{
   Derived(): Base("Derived") { cout << "Class Derived ctor called\n"; }
 };
 
 void func(Derived &d1, Derived &d2)
 {
   cout << "Assign function call\n";
   d1 = d2;
 }

int 
main ()
{
   Derived d1, d2;
   d1.A::name = strdup("Ad1");
   d2.A::name = strdup("Ad2");
   func(d1, d2); 
}
